1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.DBusServer; 26 27 private import gio.Cancellable; 28 private import gio.DBusAuthObserver; 29 private import gio.DBusConnection; 30 private import gio.InitableIF; 31 private import gio.InitableT; 32 private import gio.c.functions; 33 public import gio.c.types; 34 private import glib.ConstructionException; 35 private import glib.ErrorG; 36 private import glib.GException; 37 private import glib.Str; 38 private import glib.c.functions; 39 private import gobject.ObjectG; 40 private import gobject.Signals; 41 private import std.algorithm; 42 43 44 /** 45 * #GDBusServer is a helper for listening to and accepting D-Bus 46 * connections. This can be used to create a new D-Bus server, allowing two 47 * peers to use the D-Bus protocol for their own specialized communication. 48 * A server instance provided in this way will not perform message routing or 49 * implement the org.freedesktop.DBus interface. 50 * 51 * To just export an object on a well-known name on a message bus, such as the 52 * session or system bus, you should instead use g_bus_own_name(). 53 * 54 * An example of peer-to-peer communication with GDBus can be found 55 * in [gdbus-example-peer.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-peer.c). 56 * 57 * Note that a minimal #GDBusServer will accept connections from any 58 * peer. In many use-cases it will be necessary to add a #GDBusAuthObserver 59 * that only accepts connections that have successfully authenticated 60 * as the same user that is running the #GDBusServer. Since GLib 2.68 this can 61 * be achieved more simply by passing the 62 * %G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag to the server. 63 * 64 * Since: 2.26 65 */ 66 public class DBusServer : ObjectG, InitableIF 67 { 68 /** the main Gtk struct */ 69 protected GDBusServer* gDBusServer; 70 71 /** Get the main Gtk struct */ 72 public GDBusServer* getDBusServerStruct(bool transferOwnership = false) 73 { 74 if (transferOwnership) 75 ownedRef = false; 76 return gDBusServer; 77 } 78 79 /** the main Gtk struct as a void* */ 80 protected override void* getStruct() 81 { 82 return cast(void*)gDBusServer; 83 } 84 85 /** 86 * Sets our main struct and passes it to the parent class. 87 */ 88 public this (GDBusServer* gDBusServer, bool ownedRef = false) 89 { 90 this.gDBusServer = gDBusServer; 91 super(cast(GObject*)gDBusServer, ownedRef); 92 } 93 94 // add the Initable capabilities 95 mixin InitableT!(GDBusServer); 96 97 98 /** */ 99 public static GType getType() 100 { 101 return g_dbus_server_get_type(); 102 } 103 104 /** 105 * Creates a new D-Bus server that listens on the first address in 106 * @address that works. 107 * 108 * Once constructed, you can use g_dbus_server_get_client_address() to 109 * get a D-Bus address string that clients can use to connect. 110 * 111 * To have control over the available authentication mechanisms and 112 * the users that are authorized to connect, it is strongly recommended 113 * to provide a non-%NULL #GDBusAuthObserver. 114 * 115 * Connect to the #GDBusServer::new-connection signal to handle 116 * incoming connections. 117 * 118 * The returned #GDBusServer isn't active - you have to start it with 119 * g_dbus_server_start(). 120 * 121 * #GDBusServer is used in this [example][gdbus-peer-to-peer]. 122 * 123 * This is a synchronous failable constructor. There is currently no 124 * asynchronous version. 125 * 126 * Params: 127 * address = A D-Bus address. 128 * flags = Flags from the #GDBusServerFlags enumeration. 129 * guid = A D-Bus GUID. 130 * observer = A #GDBusAuthObserver or %NULL. 131 * cancellable = A #GCancellable or %NULL. 132 * 133 * Returns: A #GDBusServer or %NULL if @error is set. Free with 134 * g_object_unref(). 135 * 136 * Since: 2.26 137 * 138 * Throws: GException on failure. 139 * Throws: ConstructionException GTK+ fails to create the object. 140 */ 141 public this(string address, GDBusServerFlags flags, string guid, DBusAuthObserver observer, Cancellable cancellable) 142 { 143 GError* err = null; 144 145 auto __p = g_dbus_server_new_sync(Str.toStringz(address), flags, Str.toStringz(guid), (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 146 147 if (err !is null) 148 { 149 throw new GException( new ErrorG(err) ); 150 } 151 152 if(__p is null) 153 { 154 throw new ConstructionException("null returned by new_sync"); 155 } 156 157 this(cast(GDBusServer*) __p, true); 158 } 159 160 /** 161 * Gets a 162 * [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses) 163 * string that can be used by clients to connect to @server. 164 * 165 * This is valid and non-empty if initializing the #GDBusServer succeeded. 166 * 167 * Returns: A D-Bus address string. Do not free, the string is owned 168 * by @server. 169 * 170 * Since: 2.26 171 */ 172 public string getClientAddress() 173 { 174 return Str.toString(g_dbus_server_get_client_address(gDBusServer)); 175 } 176 177 /** 178 * Gets the flags for @server. 179 * 180 * Returns: A set of flags from the #GDBusServerFlags enumeration. 181 * 182 * Since: 2.26 183 */ 184 public GDBusServerFlags getFlags() 185 { 186 return g_dbus_server_get_flags(gDBusServer); 187 } 188 189 /** 190 * Gets the GUID for @server, as provided to g_dbus_server_new_sync(). 191 * 192 * Returns: A D-Bus GUID. Do not free this string, it is owned by @server. 193 * 194 * Since: 2.26 195 */ 196 public string getGuid() 197 { 198 return Str.toString(g_dbus_server_get_guid(gDBusServer)); 199 } 200 201 /** 202 * Gets whether @server is active. 203 * 204 * Returns: %TRUE if server is active, %FALSE otherwise. 205 * 206 * Since: 2.26 207 */ 208 public bool isActive() 209 { 210 return g_dbus_server_is_active(gDBusServer) != 0; 211 } 212 213 /** 214 * Starts @server. 215 * 216 * Since: 2.26 217 */ 218 public void start() 219 { 220 g_dbus_server_start(gDBusServer); 221 } 222 223 /** 224 * Stops @server. 225 * 226 * Since: 2.26 227 */ 228 public void stop() 229 { 230 g_dbus_server_stop(gDBusServer); 231 } 232 233 /** 234 * Emitted when a new authenticated connection has been made. Use 235 * g_dbus_connection_get_peer_credentials() to figure out what 236 * identity (if any), was authenticated. 237 * 238 * If you want to accept the connection, take a reference to the 239 * @connection object and return %TRUE. When you are done with the 240 * connection call g_dbus_connection_close() and give up your 241 * reference. Note that the other peer may disconnect at any time - 242 * a typical thing to do when accepting a connection is to listen to 243 * the #GDBusConnection::closed signal. 244 * 245 * If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD 246 * then the signal is emitted in a new thread dedicated to the 247 * connection. Otherwise the signal is emitted in the 248 * [thread-default main context][g-main-context-push-thread-default] 249 * of the thread that @server was constructed in. 250 * 251 * You are guaranteed that signal handlers for this signal runs 252 * before incoming messages on @connection are processed. This means 253 * that it's suitable to call g_dbus_connection_register_object() or 254 * similar from the signal handler. 255 * 256 * Params: 257 * connection = A #GDBusConnection for the new connection. 258 * 259 * Returns: %TRUE to claim @connection, %FALSE to let other handlers 260 * run. 261 * 262 * Since: 2.26 263 */ 264 gulong addOnNewConnection(bool delegate(DBusConnection, DBusServer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 265 { 266 return Signals.connect(this, "new-connection", dlg, connectFlags ^ ConnectFlags.SWAPPED); 267 } 268 }